package com.travelgroup.controller;

import com.travelgroup.domain.dto.JoinDTO;
import com.travelgroup.exception.R;
import com.travelgroup.service.IPaymentOrderService;
import com.travelgroup.service.ITourGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/pay")
@Tag(name = "支付模块")
public class PaymentController {
    @Resource
    private ITourGroupService tourGroupService;
    @Resource
    private IPaymentOrderService paymentOrderService;

    @PostMapping("/join")
    @Operation(summary = "获取支付二维码")
    public R<Map<String, Object>> payAndJoin(@RequestBody JoinDTO joinDTO) {
        return tourGroupService.payAndJoin(joinDTO);
    }

    @PostMapping("/callback")
    @Operation(summary = "支付回调")
    public R<?> paymentCallback(HttpServletRequest request) {
        return tourGroupService.paymentCallback(request);
    }

    @DeleteMapping("/cancel")
    @Operation(summary = "取消支付")
    public R<?> cancelPayment(@RequestParam String orderNo) {
        return paymentOrderService.cancelPayment(orderNo);
    }

}
